package com.muyu.danmo.service.impl;

import com.muyu.common.core.utils.DateUtils;
import com.muyu.danmo.domain.DanmoFamous;
import com.muyu.danmo.domain.DanmoFamousCard;
import com.muyu.danmo.mapper.DanmoFamousCardMapper;
import com.muyu.danmo.req.DanmoFamousNameReq;
import com.muyu.danmo.req.DanmoSelectFamousCarReq;
import com.muyu.danmo.service.IDanmoFamousCardService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 名帖字库Service业务层处理
 *
 * @author yangle
 * @date 2024-09-23
 */
@Service
public class DanmoFamousCardServiceImpl implements IDanmoFamousCardService
{
    @Autowired
    private DanmoFamousCardMapper danmoFamousCardMapper;

    /**
     * 查询名帖字库
     *
     * @param id 名帖字库主键
     * @return 名帖字库
     */
    @Override
    public DanmoFamousCard selectDanmoFamousCardById(Long id)
    {
        return danmoFamousCardMapper.selectDanmoFamousCardById(id);
    }

    /**
     * 查询名帖字库列表
     *
     * @param danmoFamousCard 名帖字库
     * @return 名帖字库
     */
    @Override
    public List<DanmoFamousCard> selectDanmoFamousCardList(DanmoFamousCard danmoFamousCard)
    {
        return danmoFamousCardMapper.selectDanmoFamousCardList(danmoFamousCard);
    }

    /**
     * 新增名帖字库
     *
     * @param danmoFamousCard 名帖字库
     * @return 结果
     */
    @Override
    public int insertDanmoFamousCard(DanmoFamousCard danmoFamousCard)
    {
        danmoFamousCard.setCreateTime(DateUtils.getNowDate());
        return danmoFamousCardMapper.insertDanmoFamousCard(danmoFamousCard);
    }

    /**
     * 修改名帖字库
     *
     * @param danmoFamousCard 名帖字库
     * @return 结果
     */
    @Override
    public int updateDanmoFamousCard(DanmoFamousCard danmoFamousCard)
    {
        danmoFamousCard.setUpdateTime(DateUtils.getNowDate());
        return danmoFamousCardMapper.updateDanmoFamousCard(danmoFamousCard);
    }

    /**
     * 批量删除名帖字库
     *
     * @param ids 需要删除的名帖字库主键
     * @return 结果
     */
    @Override
    public int deleteDanmoFamousCardByIds(Long[] ids)
    {
        return danmoFamousCardMapper.deleteDanmoFamousCardByIds(ids);
    }

    /**
     * 删除名帖字库信息
     *
     * @param id 名帖字库主键
     * @return 结果
     */
    @Override
    public int deleteDanmoFamousCardById(Long id)
    {
        return danmoFamousCardMapper.deleteDanmoFamousCardById(id);
    }

    @Override
    public DanmoFamous selectFamousName(DanmoFamousNameReq danmoFamousNameReq) {
        String preferred = danmoFamousNameReq.getPreferred();
        String[] parts = preferred.split("·");
        String author = parts[0].trim(); // 前半部分
        String workName = parts[1].trim();  // 后半部分
       List<DanmoFamousCard> list= danmoFamousCardMapper.selectFamousName(author, workName);
        DanmoFamous danmoFamous = new DanmoFamous();
        danmoFamous.setPreferred(list);
        String secondChoice = danmoFamousNameReq.getSecondChoice();
        String[] parts1 = secondChoice.split("·");
        String author1 = parts1[0].trim(); // 前半部分
        String workName1 = parts1[1].trim();  // 后半部分
       List<DanmoFamousCard> secondChoiceList= danmoFamousCardMapper.selectFamousName(author1, workName1);
        danmoFamous.setSecondChoice(secondChoiceList);
        return danmoFamous;
    }

    /**
     * 查询名帖字库列表
     * @param danmoSelectFamousCarReq
     * @return
     */
    @Override
    public List<DanmoFamous> selectFamousPicture(DanmoSelectFamousCarReq danmoSelectFamousCarReq) {
        return danmoFamousCardMapper.selectFamousPicture(danmoSelectFamousCarReq);
    }
}
